import java.util.Random;

public class 合并两个有序数组_快排 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        for(int i = m;i < m + n;i++){
            nums1[i] = nums2[i - m];
        }
        quickSort(nums1,0,nums1.length - 1);
    }

    private void quickSort(int[] nums, int left, int right) {
        if(left >= right){
            return;
        }
        int key = nums[new Random().nextInt(right - left + 1) + left];
        int l = left - 1;
        int r = right + 1;
        int i = left;
        while(i < r){
            if(nums[i] < key){
                swap(nums,++l,i++);
            }else if(key == nums[i]){
                i++;
            }else{
                swap(nums,--r,i);
            }
        }
        quickSort(nums,left,l);
        quickSort(nums,r,right);
    }

    private void swap(int[] nums, int a, int b) {
        int tmp = nums[a];
        nums[a] = nums[b];
        nums[b] = tmp;
    }
}
